package com.lvyq.myplayer.widget.song

import android.content.Context
import android.content.Intent
import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.lvyq.myplayer.R
import com.lvyq.myplayer.common.util.DataOperationUtils
import com.lvyq.myplayer.common.util.StartActivityUtils
import com.lvyq.myplayer.model.history.PlayHistoryEntity
import com.lvyq.myplayer.parcelable.SongInfoData
import com.lvyq.myplayer.ui.activity.history.ItemBatchActivity

/**
 * 文件描述：CommonSongView 最近播放
 * 作者：lvyq
 * 创建时间：2025-06-03
 * 修改时间：2025-06-03
 */
class CommonSongTopView: RelativeLayout, View.OnClickListener {
    lateinit var playAll : LinearLayout
    lateinit var selectOperate : ImageView
    lateinit var songTitle:TextView

    var list=ArrayList<PlayHistoryEntity>()

    var listSong=ArrayList<SongInfoData>()

    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    init {
        var view = View.inflate(context, R.layout.item_common_song_top, this)
        playAll=findViewById(R.id.playAll)
        selectOperate=findViewById(R.id.selectOperate)
        songTitle=findViewById(R.id.songTitle)

        selectOperate.setOnClickListener(this)
        playAll.setOnClickListener(this)

    }

    /**
     * 点击所有信息
     */
    override fun onClick(v: View?) {
        when(v?.id){
            R.id.playAll->{
                //播放全部，默认第一条
                StartActivityUtils.startAudioPlayerActivityAndSaveDB(context,listSong,0)
            }
            R.id.selectOperate->{
                //批量操作界面
                var intent = Intent(context, ItemBatchActivity::class.java)
               context.startActivity(intent)
            }
        }
    }

    fun setData(listData: ArrayList<SongInfoData>) {
        listSong.clear();
        listSong.addAll(listData)
        songTitle.text="播放全部(共"+listData.size+"首)"
    }


}